import Vue from "vue";
// import Router from "vue-router";
import Router from "../vue-router/index";
import Home from "../views/home.vue";
import About from "../views/about.vue";

Vue.use(Router);

const routes = [
  {
    path: "/",
    name: "home",
    component: Home,
    children: [
      {
        path: "a",
        component: {
          render: (h) => <h2>Home-a</h2>
        }
      },
      {
        path: "b",
        component: {
          render: (h) => <h2>Home-b</h2>
        }
      }
    ]
  },
  {
    path: "/about",
    name: "about",
    component: About,
    children: [
      {
        path: "a",
        component: {
          render: (h) => <h2>About-a</h2>
        }
      },
      {
        path: "b",
        component: {
          render: (h) => <h2>About-b</h2>
        }
      }
    ]
  },
]

const router = new Router({
  mode: "history",
  routes
})


router.matcher.addRoutes([{
  path: "/xxx666",
  name: "about",
  component: About,
}])

router.matcher.addRoute({
  path: "/xxx",
  name: "about",
  component: About,
})

// router.beforeEach((from, to, next) => {
//   setTimeout(() => {
//     console.log("触发router.beforeEach，1秒跳转---", from, to);
//     next()
//   }, 1000)
// })

// router.beforeEach((from, to, next) => {
//   setTimeout(() => {
//     console.log("触发router.beforeEach，2秒跳转---");
//     next()
//   }, 2000)
// })

export default router
